package io.github.source.bean;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName: Config
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author: huangrongcai
 * @date: 2024/6/4
 * @Copyright: 黄嵘才（HuangRc)
 */
public class Rule {

    @SerializedName("name")
    private String name;
    @SerializedName("hosts")
    private List<String> hosts;
    @SerializedName("regex")
    private List<String> regex;
    @SerializedName("script")
    private List<String> script;
    @SerializedName("exclude")
    private List<String> exclude;

    public static List<Rule> arrayFrom(JsonElement element) {
        Type listType = new TypeToken<List<Rule>>() {
        }.getType();
        List<Rule> items = new Gson().fromJson(element, listType);
        return items == null ? Collections.emptyList() : items;
    }

    public static Rule create(String name) {
        return new Rule(name);
    }

    public Rule() {
    }

    public Rule(String name) {
        this.name = name;
    }

    public static Rule empty() {
        return new Rule("");
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setHosts(List<String> hosts) {
        this.hosts = hosts;
    }

    public void setRegex(List<String> regex) {
        this.regex = regex;
    }

    public void setScript(List<String> script) {
        this.script = script;
    }


    public List<String> getHosts() {
        return hosts == null ? Collections.emptyList() : hosts;
    }

    public List<String> getRegex() {
        return regex == null ? Collections.emptyList() : regex;
    }

    public List<String> getScript() {
        return script == null ? Collections.emptyList() : script;
    }

    public List<String> getExclude() {
        return exclude == null ? Collections.emptyList() : exclude;
    }
    public void setExclude(List<String> exclude) {
        this.exclude = exclude;
    }
}
